package link

// LinkNode 链表
type LinkNode struct {
	Val  int
	Next *LinkNode
}

// GetLinkReverse 反转
func GetLinkReverse(head *LinkNode) *LinkNode {
	var pre *LinkNode
	cur := head
	for cur != nil {
		next := cur.Next
		cur.Next = pre
		pre = cur
		cur = next
	}
	return pre
}

// GetMiddleLink 获取中间节点
func GetMiddleLink(head *LinkNode) *LinkNode {
	fast, slow := head, head
	for fast != nil && fast.Next != nil {
		fast = head.Next.Next
		slow = head.Next
	}
	return slow
}
